refactor:add parallelization optimization to bpcg#7416
Open
Missing-Hex wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenMP Parallelization for BPCG CPU Kernels
Summary
This PR implements OpenMP parallelization for the two hotspot functions in the BPCG (Block Preconditioned Conjugate Gradient) diagonalization algorithm:
line_minimize_with_block_op<CPU>calc_grad_with_block_op<CPU>Motivation
The BPCG algorithm is an iterative diagonalization method used in ABACUS for solving the Kohn-Sham equations. Profiling shows that
line_minimize_with_block_opandcalc_grad_with_block_opare the primary hotspots within each iteration, consuming significant CPU time when processing multiple bands.Since bands are independent of each other and access disjoint memory regions, parallelizing over the band dimension is both safe and efficient.
Changes Made
1. Parallelization Strategy
Both functions are restructured into multi-phase pipelines that separate compute-intensive loops from MPI collective operations:
#pragma omp parallel for schedule(static)Parallel_Reduce::reduce_pool()2. Key Technical Decisions
Thread Safety
MPI_AllreduceviaParallel_Reduce::reduce_pool) are not thread-safe and are executed serially outside parallel regionsBatched MPI Reduction
Static Scheduling
schedule(static)is used because each band has equal workload (n_basisoperations)Conditional Compilation
#ifdef _OPENMP3. Memory Access Pattern
Each band accesses a contiguous memory block:
This ensures:
Performance Impact
Theoretical Speedup
n_band)Expected Behavior
n_bandon multi-core systemsCode Structure
line_minimize_with_block_op<CPU>(5 phases)calc_grad_with_block_op<CPU>(7 phases)Testing
Files Modified
source/source_hsolver/kernels/bpcg_kernel_op.cppBackward Compatibility
Notes
The parallelization follows the same pattern already used in
refresh_hcc_scc_vcc_opwithin the same file, ensuring consistency with existing codebase conventions.